package com.acwing.partition13;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/11 12:52
 */
public class AC1250格子游戏 {

    private static final int N = 40010;
    private static int[] parent = new int[N];
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        for (int i = 0; i < n * n; i++) parent[i] = i;
        int m = Integer.parseInt(ss[1]), ans = 0;
        for (int i = 1; i <= m; i++) {
            ss = reader.readLine().split(" ");
            int x = Integer.parseInt(ss[0]) - 1, y = Integer.parseInt(ss[1]) - 1, a = x * n + y;
            char dir = ss[2].charAt(0);
            int b = 0;
            if (dir == 'D') b = (x + 1) * n + y;
            else b = x * n + y + 1;
            int pa = find(a), pb = find(b);
            if (pa == pb) {
                ans = i;
                break;
            }
            parent[pa] = pb;
        }
        if (ans == 0) writer.write("draw\n");
        else writer.write(ans + "\n");
        writer.flush();
    }

    private static int find(int x) {
        if (parent[x] != x) parent[x] = find(parent[x]);
        return parent[x];
    }
}
